package org.example;

import org.example.biz.Computer;
import org.example.biz.HelloBiz;
import org.example.dao.Storage;
import org.example.dao.UsbDisk;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {IocConfig.class})
public class SpringTestDemo {

    @Autowired
    Computer computer;

    // UsbDisk 实现了接口, 在被增强的情况下, 会出现异常
    // @Autowired
    // UsbDisk usbDisk;  // 错误
    @Autowired
    @Qualifier("usbDisk")
    Storage usbDisk;

    @Test
    public void test1(){
        computer.save("Java 源代码");
    }

    @Autowired
    HelloBiz helloBiz;

    @Test
    public void test2(){
        System.out.println("--------------------------");
        helloBiz.hello();
        System.out.println("--------------------------");
        helloBiz.test();
        System.out.println("--------------------------");
        System.out.println("helloBiz.opAdd(1,2) = " + helloBiz.opAdd(1, 2));
        System.out.println("--------------------------");
        System.out.println("helloBiz.opSub(10,2) = " + helloBiz.opSub(10, 2));
        System.out.println("--------------------------");
        System.out.println("helloBiz.opSub(1,0) = " + helloBiz.opSub(1, 0));
        System.out.println("--------------------------");
    }



}
